package com.lz.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.lz.form.UploadItemDTO;
import com.lz.service.UploadItemService;

public class PrevPageAction extends DispatchAction {

    String filePath = "";

    public ActionForward execute(ActionMapping mapping, ActionForm form,
	    HttpServletRequest request, HttpServletResponse response)
	    throws Exception {
	HttpSession session = request.getSession(true);
	UploadItemDTO uform = (UploadItemDTO) session
		.getAttribute("queryparams");
	int pageNumber = Integer.parseInt(request.getParameter("pagenumber"));
	int end = (pageNumber - 1) * AdminSearchAction.DISPLAYCOUNT;

	if (end == 0) {
	    end = AdminSearchAction.DISPLAYCOUNT;

	    request.setAttribute("message", "No Previous records");
	    return mapping.findForward("MESSAGE");

	}

	ArrayList list = UploadItemService.getSearchResult(uform, uform
		.getOrderby(), "" + (end - AdminSearchAction.DISPLAYCOUNT),
		"" + AdminSearchAction.DISPLAYCOUNT);
	uform.setShopid("1");
	uform.setImageList(list);
	pageNumber--;
	request.setAttribute("pagenumber", "" + pageNumber);
	session.setAttribute("queryparams", uform);

	return mapping.findForward(uform.getForward());
    }

}
